package study.javabasic.sort;

import java.util.Arrays;
import java.util.List;

public class BubblingSort {

    public static void main(String[] args) {
        Integer[] j = {1, 1, 4, 3, 4, 6, 9, 7, 8};
        j = bubblingSort(j);
        System.out.println(Arrays.toString(j));
    }


    private static Integer[] bubblingSort(Integer[] nums) {

        for (int i = nums.length - 1; i >= 0; i--) {
            //从后往前遍历 取出最大值放在后面位置
            int tem = nums[i];
            //从后往前遍历
            int k = i - 1;
            int t = i;
            if (i - 1 < 0) {
                break;
            }
            int now = tem;
            for (int k1 = k; k1 > 0; k1--) {
                int intem = nums[k1];
                if (intem > tem) {
                    now = intem;
                    t = k1;
                }

            }
            nums[i] = now;
            nums[t] = tem;
        }


        return nums;

    }
}
